home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / getstring.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, Gdk
  5. from quodlibet.qltk.entry import UndoEntry
  6. from quodlibet.qltk.window import Dialog
  7.  
  8. class GetStringDialog(Dialog):
  9.     '''Simple dialog to return a string from the user'''
  10.     _WIDTH = 300
  11.     
  12.     def __init__(self, parent, title, text, okbutton = Gtk.STOCK_OPEN):
  13.         super(GetStringDialog, self).__init__(title = title, transient_for = parent, use_header_bar = True)
  14.         self.set_border_width(6)
  15.         self.set_default_size(width = self._WIDTH, height = 0)
  16.         self.set_resizable(True)
  17.         self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, okbutton, Gtk.ResponseType.OK)
  18.         self.vbox.set_spacing(6)
  19.         self.set_default_response(Gtk.ResponseType.OK)
  20.         box = Gtk.VBox(spacing = 6)
  21.         lab = Gtk.Label(label = text)
  22.         box.set_border_width(6)
  23.         lab.set_line_wrap(True)
  24.         lab.set_justify(Gtk.Justification.CENTER)
  25.         box.pack_start(lab, True, True, 0)
  26.         self._val = UndoEntry()
  27.         box.pack_start(self._val, True, True, 0)
  28.         self.vbox.pack_start(box, True, True, 0)
  29.         self.get_child().show_all()
  30.  
  31.     
  32.     def _verify_clipboard(self, text):
  33.         '''Return an altered text or None if the content was invalid.'''
  34.         pass
  35.  
  36.     
  37.     def run(self, text = '', clipboard = False, test = False):
  38.         '''Shows the dialog and returns the entered value.
  39.  
  40.         If clipboard is set, the initial value will be pulled from the
  41.         clipboard and can be verified/altered by _verify_clipboard. In case the
  42.         verification fails text will be used as fallback'''
  43.         self.show()
  44.         if clipboard:
  45.             clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
  46.             clip = clipboard.wait_for_text()
  47.             if clip is not None:
  48.                 clip = self._verify_clipboard(clip)
  49.             if clip is not None:
  50.                 text = clip
  51.             
  52.         self._val.set_text(text)
  53.         self._val.set_activates_default(True)
  54.         self._val.grab_focus()
  55.         resp = Gtk.ResponseType.OK
  56.         if not test:
  57.             resp = super(GetStringDialog, self).run()
  58.         if resp == Gtk.ResponseType.OK:
  59.             value = self._val.get_text()
  60.         else:
  61.             value = None
  62.         self.destroy()
  63.         return value
  64.  
  65.  
  66.